package pl.bristleback.server.bristle.mocks;

import org.apache.log4j.Logger;
import pl.bristleback.server.bristle.states.ServerStateListener;
import pl.bristleback.server.bristle.states.ServerStateListenerChain;

/**
 * Server state listener implementation used in tests.
 * <p/>
 * Created on: 2010-11-10 13:03:23 <br/>
 *
 * @author Wojciech Niemiec
 */
public class ServerStateListenerMock implements ServerStateListener {
  private static Logger log = Logger.getLogger(ServerStateListenerMock.class.getName());

  public static final String SERVER_STATE_STARTED = "serverStarted";
  public static final String SERVER_STATE_STOPPED = "serverStopped";

  private boolean cancelChain;
  private String serverState;

  public ServerStateListenerMock(boolean cancelChain) {
    this.cancelChain = cancelChain;
  }

  @Override
  public void onServerStart(ServerStateListenerChain listenerChain) {
    serverState = SERVER_STATE_STARTED;
    if (cancelChain) {
      listenerChain.cancelChain();
    }
  }

  @Override
  public void onServerStop(ServerStateListenerChain listenerChain) {
    serverState = SERVER_STATE_STOPPED;
    if (cancelChain) {
      listenerChain.cancelChain();
    }
  }

  public String getServerState() {
    return serverState;
  }
}
